<?php
/**
 * HTML page for showing single blogposts (permalink page)
 *
 * @version 0.1 
 * @license MIT License http://www.opensource.org/licenses/mit-license.php
 * @copyright (c) 2007 Geir Arne Brevik
 * @author Geir Arne Brevik
 */
include_once('lib.php'); // include bootstrapping and helper functions

// set the edit flag
$slug_exists = (isset($_GET['s']) and slugExists($_GET['s'], 'posts')) ? true : false;
if ($slug_exists){
	$blogpost = new MiniBlog(getIdFromField('posts', 'slug', $_GET['s']));
	$doc_title = $blogpost->title;	
} else { // 404 message
	header("HTTP/1.1 404 Not Found");
	$doc_title = 'Page was not found';
}

include('meta.php');
include('header.php');

if($slug_exists){ // print blogpost
	echo(filter($blogpost->body));
	?><p class="credits">By <?php echo(userLink($blogpost->created_by).', '.showDate($blogpost->created_at)); ?></p><?php
} else { // show 404 message
	?><p>The page could not be found. Please check the address.</p><?php
}

include('footer.php');
?>